<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>
  
  <head>    
    <title>How to import a custom model with 1 in-game material</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link href="../../styles.css" rel="stylesheet">
    <link rel="icon" href="../../images/icon.png">
	</head>

	<body>

    <div id="top">
      <h1>How to import a custom model with 1 in-game material</h1> 
    </div>
			
    <div id="hot-links">
      <h2>Direct links</h2>
      <hr>
      <ol>
        <li><a href="../../index.html">Introduction</a></li>
        <li><a href="../tutorials.html">Tutorials</a></li>
        <li><a href="../resources.html">Resources</a></li>
      </ol>
    </div>
			
    <div id="main">
      
      <h2>Contents</h2>
      <hr>
      <ol>
        <li><a href="#tools">Required tools</a></li>
        <li><a href="#warnings">Warnings</a></li>
        <li><a href="#steps">Steps</a></li>
        <li><a href="#extra">Some extra explanations</a></li>
      </ol>
      <br>

      <hr id="tools">
      <h2>Required tools</h2>
      <hr>
      <p>Go to <a href="../resources.html">Resources</a> for download links.</p>        
      <ul>
        <li>Blender</li>
        <li>SuperBMD</li>
        <li>j3dview</li>
        <li>Any text editor you like (Notepad++ is recommended)</li>
        <li>Collision Creator</li>
        <li>Arc Convertor</li>
        <li>Whitehole</li>
        <li>Wiimm's ISO Tools (to get your SMG1 dump)</li>
      </ul>
      <br>

      <hr>
      <h2>Required tutorials</h2>
      <hr>
      <ul>
        <li><a href="t1.html">How to import a custom model into SMG1</a></li>
      </ul>
      <br>

      <hr id="warnings">
      <h2>Warnings</h2>
      <hr>
      <ol>
        <li>I will be dealing with a <b>SuperBMD bug</b> that has not been corrected yet. It can be bypassed by using <b>j3dview</b> (I will explain this on the tutorial).</li>      
        <li>This tutorial is only to import a model with <b>1 in-game material</b>. The next tutorial will be for <b>2 and more</b>. The reason I made this distinction is because I believe this is the fastest way to import a model with <b>1 in-game material only</b>, when using 2 or more you have to be more organized.</li>
      </ol>
      <br>

      <hr id="steps">
      <h2>Steps --- files used: <a href="https://archive.org/download/humming-owl-storage/tutorial2.zip">tutorial2.zip</a></h2>
      <hr>

      <p>First we need to know the <b>in-game material</b> we want to extract. Open <b>Whitehole</b> and search around the galaxies for the object that has the material you want. I will choose the material this planet has as grass. It is located in <code>Good Egg Galaxy</code> (<b>Fig. 1</b>).</p>

      <img src="../../images/t2/fig1.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 1 - Whitehole search for model containing desired material)</p>
      <br>

      <p>Click on the desired object and look for its <b>Object property</b> (you will need this value), in my case the <b>Object</b> is <code>BroadBeanPlanetB</code> (<b>Fig. 2</b>). You can now close <b>Whitehole</b> and go to the <code>ObjectData</code> folder of your <b>SMG1 dump</b>. In there you will look for an <b>ARC file</b> named exactly as the <b>Object value</b> you got from before, in my case that would be the <code>BroadBeanPlanetB.arc</code> file (<b>Fig. 3</b>). This is the file that contains the planet model from <b>Fig. 1</b>. Just to keep things organized, create a folder named <code>game-materials</code> on your <b>SMG working environment</b> and place the <b>ARC file</b> inside a folder that has the same name as the <b>ARC file</b> (subject to personal preference, <b>Fig. 4</b>).</p>

      <img src="../../images/t2/fig2.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 2 - Model's object property)</p>
      <br>

      <img src="../../images/t2/fig3.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 3 - ARC file in ObjectData folder containing desired model)</p>
      <br>

      <img src="../../images/t2/fig4.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 4 - Optional organization method)</p>
      <br>

      <p>Now create a <b>new window</b>, locate the <b>Arc Convertor</b> tool and <b>drag and drop the ARC file</b> extracted into to the <code>arcExtract.exe</code> file. A few <b>new files</b> will appear in the same location as the <b>ARC file</b> (depending on the object there will be more or less files, <b>Fig. 5</b>).</p>

      <img src="../../images/t2/fig5.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 5 - Extract ARC file contents)</p>
      <br>

      <p>Locate the <b>BDL/BMD file</b> (file containing the <b>3D model</b> of the object) and in the other window search for the <b>SuperBMD</b> tool. <b>Drag and drop</b> the <b>BDL file</b> into the <code>SuperBMD.exe</code> file. Several <b>more files</b> will appear on the same location as the <b>BDL/BMD file</b> (<b>Fig. 6</b>).</p>

      <img src="../../images/t2/fig6.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 6 - Extract BDL/BMD file contents)</p>
      <br>

      <p>The file we want to get right now is the <b>DAE file</b> created by <b>SuperBMD</b>. This is the <b>3D model</b> of the object containing our desired material in a file format that can be opened on <b>Blender</b>. Open <b>Blender</b>, go to <code>File > Import > Collada (Default) (.dae)</code> (<b>Fig. 7</b>) and search for the <b>DAE file</b> from before. After selecting it, the model will show up on <b>Blender</b>. It will show very big so <b>scale it down</b> to a reasonable size (<b>Fig. 8</b>).</p>

      <img src="../../images/t2/fig7.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 7 - Import DAE file to Blender)</p>
      <br>

      <img src="../../images/t2/fig8.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 8 - Imported DAE model scaled to 0.01)</p>
      <br>

      <p>With the <b>object file</b> in <b>Blender</b> we can now see the <b>materials</b> that are assigned to this object. Go to the <b>Materials tab</b> and right-click on the face you know your material is present. In this case the object is <b>simple</b> and is only composed by <b>2 fragments</b> (the cube and the planet, <b>Fig. 9</b>). The <b>material</b> we want for our model is called <code>m0BeanFace_v</code> (<b>Fig. 9</b>). Until now, this was only <b>to get the name of the material we wanted</b>. You can now close <b>Blender</b>.</p>

      <img src="../../images/t2/fig9.jpg" alt="Image could not be loaded.">

      <p class="idtext">(Fig. 9 - Watching materials assigned of imported model)</p>
      <br>
      
      <hr>
      <p><b>NOTE 1:</b> In some cases the material we want won’t be exactly on the place we think it is so you have to search its texture associated to see if it is actually the material you want.</p>
      <hr>
      <br>

      <p>Now, go and open with your favorite <b>text editor</b> the <code>[ARC filename]_materials.json</code> file located in the same place as the <b>DAE file</b> (I will use <b>Notepad++</b> on <b>Windows</b>). This is the file containing the information of all the materials coded into the <b>BDL file</b> from before (<b>Figs. 10 and 11</b>).</p>

      <img src="../../images/t2/fig10.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 10 - JSON files)</p>
      <br>

      <img src="../../images/t2/fig11.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 11 - Material JSON file opened on <code>Notepad++</code>)</p>
      <br>
      
      <hr>
      <p><b>NOTE 2:</b> the <code>[ARC filename]_tex_headers.json</code> <b>file</b> contains the information about the <b>textures</b> assigned to the <b>materials</b> from the <code>[ARC filename]_materials.json</code> <b>file</b>.</p>
      <hr>
      
      <br>

      <p>Remove the <b>first 2 or 3 letters</b> from the <b>material’s</b> name extracted from <b>Blender</b> (the actual <b>material name</b> is the one after those letters) and search for that name on the <b>text editor</b> (in my case it is named <code>BeanFace_v</code>, <b>Fig. 12</b>).</p>

      <img src="../../images/t2/fig12.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 12 - Real material name)</p>
      <br>

      <p>The <code>Name</code> property is the name of the material, and what exists in the <code>TextureNames</code> property are the <b>textures</b> used by that <b>material</b> (<b>Fig. 13</b>).</p>

      <img src="../../images/t2/fig13.jpg" alt="Image could not be loaded.">

      <p class="idtext">(Fig. 13 - Watching a material and the textures assigned to it)</p>

      <br>

      <p>As we can see (<b>Fig. 13</b>) the <b>textures</b> used by the <b>material</b> are <code>Grasses001HighColorLoop02LightGray:0</code>, <code>BeanHighLight:0</code> and <code>Grasses001HighColorLoop02LightGray:0</code>. By removing the <code>:0</code> at the end of each entry you will find on the same directory the <b>ARC file</b> is, <b>PNG files</b> that carry those names, those are the <b>textures</b> (<b>Fig. 14</b>). You may have thought, a texture repeats twice? yes, they can repeat several times and we will use that later.</p>

      <img src="../../images/t2/fig14.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 14 - Textures used by the material we want)</p>
      <br>
      
      <hr>
      <p><b>NOTE 3:</b> the <b>PNGs</b> with the <code>mip</code> string in their name are <b>mipmaps of a specific PNG file</b> and they have always a lower resolution than the main <b>PNG file</b>.</p>
      <hr>
      <br>

      <p>Now let’s go and open our model to apply those <b>textures</b> on (I will apply the <b>material</b> to an <b>UV sphere</b>, <b>Fig. 15</b>). </p>

      <img src="../../images/t2/fig15.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 15 - Example model)</p>
      <br>

      <p>Set a <b>material</b> in <b>Blender</b> and assign it to the faces of the object you want. Change its name to the name of the <b>material</b> extracted from before (in my case it will be named <code>BeanFace_v</code>, <b>Fig. 16</b>).</p>

      <img src="../../images/t2/fig16.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 16 - Example model)</p>
      <br>

      <p>Now set the respective <b>textures</b> to that <b>material</b> keeping the order and the repetition of the <b>texture list</b> of the <b>material</b> in the <b>material JSON file</b> (you don’t need to apply specific names to the textures, <b>Fig. 17 and 13</b>).</p>

      <img src="../../images/t2/fig17.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 17 - Assigning the textures from the material)</p>
      <br>

      <p><b>Unwrap or apply a Smart UV Project</b> and modify the looks of your <b>textures</b> as you wish (apply <b>vertex paint</b> for example or <b>smooth shading</b>), triangulate, scale and export your model into <b>FBX</b> and <b>OBJ</b> to a known path (place your textures in the same place the exported files are) and then locate your exports to continue with the tutorial (<b>Fig. 18</b>).</p>

      <img src="../../images/t2/fig18.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 18 - Exported files from <code>Blender</code> with the texture files used)</p>
      <br>

      <p>Copy both <b>JSON files</b> in the same place the exported files are (<b>Fig. 19</b>).</p>

      <img src="../../images/t2/fig19.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 19 - JSON files copied)</p>
      <br>

      <p>Remove the <b>textures</b> from the copied <code>[ARC filename]_tex_headers.json</code> <b>file</b> that you aren’t using (<b>Fig. 20</b>) and save the document (if you don’t do this <b>SuperBMD</b> will crash). And then open a <b>CMD</b> in that folder.</p>

      <img src="../../images/t2/fig20.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 20 - Erasing unused textures from JSON file)</p>
      <br>

      <p>Type the following command into the <b>CMD</b> were <code>[your_object].fbx</code> is the <b>FBX model</b>, the <code>[ARC filename]_materials.json</code> the <b>material JSON</b> cointaning our desired <b>material data</b> and the <code>[ARC filename]_tex_headers.json</code> the <b>texture JSON</b> cointaning the <b>texture data</b>.</p>

      <p><code>path\to\SuperBMD.exe [your_object].fbx --mat [ARC filename]_materials.json --texheader [ARC filename]_tex_headers.json --rotate --nosort"</code></p>

      <br>
      <hr>
      <p><b>NOTE 4:</b> Linux users, remember to use a forward slash instead of a backslash for paths!</p>
      <hr>
      <br>

      <p>What this does is to <b>link the materials</b> in the <b>JSON file</b> with the materials you added on your <b>FBX object</b> (you had to name the <b>material</b> in <b>Blender</b> the same as the <b>material</b> from the <b>in-game object</b> to be able to make this link here).</p>

      <img src="../../images/t2/fig21.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 21 - Using SuperBMD on CMD to apply materials to model)</p>
      <br>

      <p>If everything was done correctly a <b>BMD file</b> will be created in the same directory as <b>FBX file</b> (<b>Fig. 22</b>).</p>

      <img src="../../images/t2/fig22.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 22 - BMD file creation)</p>
      <br>

      <p>Go and open the <b>BMD file</b> with <b>j3dview</b> and save it as a <b>BD</b>L (<code>File > Save Model As...</code>, <b>Fig. 23</b>). This is done because <b>SuperBMD</b> has a bug that when an <b>in-game material</b> is applied to an object, the <b>material</b> applied on the <b>imported model</b> will look <b>extremely strong on game</b>. When opening it and saving it with <b>j3dview</b> this error is corrected and the <b>material</b> will show as intended in game.</p>

      <img src="../../images/t2/fig23.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 23 - BMD file opened and saved as BDL with <b>j3dview</b>)</p>
      <br>

      <p>That <b>BDL file</b> will be the one that you will put on a folder with the <b>collision files</b> of your model, pack it as an <b>ARC file</b> and finally introduce the model on the game (<b>Fig. 24</b>). (if scaling down the UV mapping on the model on <b>Blender</b> the model looks better).</p>

      <img src="../../images/t2/fig24.jpg" alt="Image could not be loaded.">
      <p class="idtext">(Fig. 24 - Custom model with in-game material imported to SMG1)</p>
      <br>

      <hr id="extra">
      <h2>Some extra explanations</h2>
      <hr>
      
      <p><b>1</b>) The <b>materials</b> might not work exactly as intended because as they were created for the model from which they have been extracted, only models <b>similar to the original</b> one will fit the <b>material correctly</b>. With some modifications to the model on <b>Blender</b> you can get the <b>material</b> to look better (you have to learn a little more how to use <b>Blender</b>).</p>
      
      <p><b>2)</b> As we are using only <b>one material</b> I did not explain properly the <b>JSON file</b> setup. This tutorial is more intended to be a preparation to the next being with <b>2 or more in game materials</b>.</p>
      
      <p><b>3)</b> I wasn’t aware of the <b>SuperBMD</b> error, it wasn’t documented on any website I’ve found about <b>SMG modding</b>, so I had to ask on the <b>Luma’s Workshop Discord server</b>. Thanks to an user, I was able to finish this tutorial correctly (many thanks). Hopefully this error will be fixed soon.</p>
      
      <p><b>4)</b> It is best practice to save the model in <b>j3dview</b> as a <b>BDL</b> since as a <b>BMD</b> it might not look correct on the game all times.</p>
      
      <br>

    </div>

  </body>

</html>
